package com.simple.elpmobile.onlinecase.ui.base;


import com.simple.elpmobile.onlinecase.R;

import android.content.Context;
import android.graphics.Color;
import android.os.Handler;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

/**
 * 控制Toast显示
 * 新的Toast到来时，取消前一个显示
 * @author gjyuan
 *
 */
public class CustomToast {
	
	public static int LENGTH_SHORT = 1000;
	public static int LENGTH_LONG = 3000;

	private static Toast mToast;
	private static Handler mHandler = new Handler();
	private static Runnable toastCel = new Runnable() {
		public void run() {
			mToast.cancel();
		}
	};

	public static void showToast(Context mContext, String text, int duration) {

		mHandler.removeCallbacks(toastCel);
		mToast = Toast.makeText(mContext, text, duration);
		
		View layout = LayoutInflater.from(mContext).inflate(R.layout.toast_layout, null);  
        TextView toastText = (TextView) layout.findViewById(R.id.toast_text);  
        toastText.setText(text);  
        toastText.setTextColor(Color.WHITE); 
        
        mToast.setView(layout); 
		mToast.show();
		mHandler.postDelayed(toastCel, duration);

	}

	public static void showToast(Context mContext, int resId, int duration) {
		showToast(mContext, mContext.getResources().getString(resId), duration);
	}
	
	
/*	
	public static void showViewToast(Context mContext, int layoutId, int duration){
		mHandler.removeCallbacks(toastCel);
		mToast=new Toast(mContext);
		View view=View.inflate(mContext, layoutId, null);
		mToast.setView(view);
		mToast.setGravity(Gravity.CENTER, 0, 0);// 起点位置为中间 100为向下移100dp
		mToast.show();
		mHandler.postDelayed(toastCel, duration);
	}
	*/
	

}